package com.xx.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xx.system.domain.data.ShipData;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * TODO
 *
 * @Author kzw
 * @Date 2025/3/27 14:31
 */
@Mapper
public interface ShipDataMapper extends BaseMapper<ShipData> {
    @Select("SELECT t1.* FROM ship_data t1 " +
            "INNER JOIN (SELECT mmsi, MAX(time) as max_time FROM ship_data GROUP BY mmsi) t2 " +
            "ON t1.mmsi = t2.mmsi AND t1.time = t2.max_time")
    List<ShipData> selectLatestDataForEachShip();
}
